/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package javax.clear.sun.reflect.misc;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;

public class Reflection
{

    public Reflection()
    {
    }

    public static native Class getCallerClass(int i);

    private static native int getClassAccessFlags(Class class1);

    public static boolean quickCheckMemberAccess(Class class1, int i)
    {
        return Modifier.isPublic(getClassAccessFlags(class1) & i);
    }

    public static void ensureMemberAccess(Class class1, Class class2, Object obj, int i)
        throws IllegalAccessException
    {
        if(class1 == null || class2 == null)
            throw new InternalError();
        if(!verifyMemberAccess(class1, class2, obj, i))
            throw new IllegalAccessException((new StringBuilder()).append("Class ").append(class1.getName()).append(" can not access a member of class ").append(class2.getName()).append(" with modifiers \"").append(Modifier.toString(i)).append("\"").toString());
        else
            return;
    }

    public static boolean verifyMemberAccess(Class class1, Class class2, Object obj, int i)
    {
        boolean flag = false;
        boolean flag2 = false;
        if(class1 == class2)
            return true;
        if(!Modifier.isPublic(getClassAccessFlags(class2)))
        {
            flag2 = isSameClassPackage(class1, class2);
            flag = true;
            if(!flag2)
                return false;
        }
        if(Modifier.isPublic(i))
            return true;
        boolean flag3 = false;
        if(Modifier.isProtected(i) && isSubclassOf(class1, class2))
            flag3 = true;
        if(!flag3 && !Modifier.isPrivate(i))
        {
            if(!flag)
            {
                flag2 = isSameClassPackage(class1, class2);
                flag = true;
            }
            if(flag2)
                flag3 = true;
        }
        if(!flag3)
            return false;
        if(Modifier.isProtected(i))
        {
            Class class3 = obj != null ? obj.getClass() : class2;
            if(class3 != class1)
            {
                if(!flag)
                {
                    flag2 = isSameClassPackage(class1, class2);
                    boolean flag1 = true;
                }
                if(!flag2 && !isSubclassOf(class3, class1))
                    return false;
            }
        }
        return true;
    }

    private static boolean isSameClassPackage(Class class1, Class class2)
    {
        return isSameClassPackage(class1.getClassLoader(), class1.getName(), class2.getClassLoader(), class2.getName());
    }

    private static boolean isSameClassPackage(ClassLoader classloader, String s, ClassLoader classloader1, String s1)
    {
        if(classloader != classloader1)
            return false;
        int i = s.lastIndexOf('.');
        int j = s1.lastIndexOf('.');
        if(i == -1 || j == -1)
            return i == j;
        int k = 0;
        int l = 0;
        if(s.charAt(k) == '[')
        {
            do
                k++;
            while(s.charAt(k) == '[');
            if(s.charAt(k) != 'L')
                throw new InternalError((new StringBuilder()).append("Illegal class name ").append(s).toString());
        }
        if(s1.charAt(l) == '[')
        {
            do
                l++;
            while(s1.charAt(l) == '[');
            if(s1.charAt(l) != 'L')
                throw new InternalError((new StringBuilder()).append("Illegal class name ").append(s1).toString());
        }
        int i1 = i - k;
        int j1 = j - l;
        if(i1 != j1)
            return false;
        else
            return s.regionMatches(false, k, s1, l, i1);
    }

    static boolean isSubclassOf(Class class1, Class class2)
    {
        for(; class1 != null; class1 = class1.getSuperclass())
            if(class1 == class2)
                return true;

        return false;
    }

    public static void registerFieldsToFilter(Class class1, String as[])
    {
        fieldFilterMap.put(class1, as);
    }

    public static Field[] filterFields(Class class1, Field afield[])
    {
        if(fieldFilterMap == null)
            return afield;
        String as[] = (String[])(String[])fieldFilterMap.get(class1);
        if(as == null)
            return afield;
        int i = 0;
        for(int j = 0; j < afield.length; j++)
        {
            boolean flag = false;
            Field field = afield[j];
            int i1 = 0;
            do
            {
                if(i1 >= as.length)
                    break;
                if(field.getName() == as[i1])
                {
                    flag = true;
                    break;
                }
                i1++;
            } while(true);
            if(!flag)
                i++;
        }

        Field afield1[] = new Field[i];
        int k = 0;
        for(int l = 0; l < afield.length; l++)
        {
            boolean flag1 = false;
            Field field1 = afield[l];
            int j1 = 0;
            do
            {
                if(j1 >= as.length)
                    break;
                if(field1.getName() == as[j1])
                {
                    flag1 = true;
                    break;
                }
                j1++;
            } while(true);
            if(!flag1)
                afield1[k++] = field1;
        }

        return afield1;
    }

    private static Map fieldFilterMap = Collections.synchronizedMap(new HashMap());

}